program BuildVersion;

{$APPTYPE CONSOLE}

uses
  Classes, windows, SysUtils, IniFiles;

var
  ini:TMemIniFile;
  Result :  Integer;
  SearchRec : TSearchRec;
  l:TStringList;


procedure sets(const s:string);
var
  v:string;
begin
  v := ini.ReadString('Version Info Keys', s, '');
  l.Add( '  ver_' + s + '=''' + v + ''';' );
  if v <> '' then
    writeln(s, ': ', v);
end;

procedure extract_info(const f:string);
begin
  l.Clear;
  ini.Rename(f, True);
  writeln('Plik: ', ExtractFileName(f));
  l.Add('const');
  sets('CompanyName');
  sets('FileDescription');
  sets('FileVersion');
  sets('InternalName');
  sets('LegalCopyright');
  sets('LegalTrademarks');
  sets('OriginalFilename');
  sets('ProductName');
  sets('ProductVersion');
  sets('Comments');
  l.Add( '  ver_DateString=''' + formatDateTime('yyyy-mm-dd hh:mm:ss:zzz', Now()) + ''';' );
  l.SaveToFile(ChangeFileExt(f, '.inc'));
  writeln('----');
end;


begin
  ini := TMemIniFile.Create('');
  l := TStringList.Create();
  try
    SetCurrentDir(ExtractFilePath(ParamStr(0)));
    Result := FindFirst('*.dof', faAnyFile and not faDirectory, SearchRec);
    while Result = 0 do
    begin
      extract_info(SearchRec.Name);
      Result := FindNext(SearchRec);
    end;
    FindClose(SearchRec);
  finally
    l.Free;
    ini.Free;
  end;
  ExitProcess(0);
end.
